﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ImageTagEditor
{
	/// <summary>
	/// Interaction logic for PowerToolTip.xaml
	/// </summary>
	public partial class PowerToolTip : UserControl
	{
		/// <summary>
		/// Create a new Power Toll Tip
		/// </summary>
		public PowerToolTip()
		{
			InitializeComponent();
			UpdateVisualsForErrors();
		}


		/// <summary>
		/// Get or set the Header
		/// </summary>
		public string Header
		{
			get { return (string)GetValue(HeaderProperty);}
			set { SetValue(HeaderProperty, value); }
		}

		/// <summary>
		/// Identifies the Header dependency property
		/// </summary>
		public static readonly DependencyProperty HeaderProperty =
			DependencyProperty.Register("Header", typeof(string), typeof(PowerToolTip), new UIPropertyMetadata("HEADER"));




		/// <summary>
		/// Get or set the Error
		/// </summary>
		public string Error
		{
			get { return (string)GetValue(ErrorProperty); }
			set { SetValue(ErrorProperty, value); }
		}


		/// <summary>
		/// Identifies the Error dependency property
		/// </summary>
		public static readonly DependencyProperty ErrorProperty =
			DependencyProperty.Register("Error", typeof(string), typeof(PowerToolTip), new UIPropertyMetadata(string.Empty, OnErrorChanged));


		/// <summary>
		/// Dependency Property Error changed listener
		/// </summary>
		/// <param name="sender">The PowerToolTip whose dependency property changed</param>
		/// <param name="e">The event args that came with the change</param>
		protected static void OnErrorChanged(object sender, DependencyPropertyChangedEventArgs e)
		{
			(sender as PowerToolTip).OnErrorChanged(e);
		}

		/// <summary>
		/// Listens for when the Error Dependency Property value changes.
		/// </summary>
		/// <param name="e">Not Used</param>
		protected void OnErrorChanged(DependencyPropertyChangedEventArgs e)
		{
			UpdateVisualsForErrors();
		}

		/// <summary>
		/// Sets the visuals indications on the power tool tip to show
		/// whether an error has occured or not
		/// </summary>
		private void UpdateVisualsForErrors()
		{
			if (String.IsNullOrEmpty(Error))
			{
				errorTextBlock.Visibility = Visibility.Collapsed;
				headerTextBlock.Background = (Brush)FindResource("okayColor");
				headerTextBlock.Foreground = (Brush)FindResource("headerOkayFontColor");
			}
			else
			{
				errorTextBlock.Visibility = Visibility.Visible;
				headerTextBlock.Background = (Brush)FindResource("errorColor");
				headerTextBlock.Foreground = (Brush)FindResource("headerErrorFontColor");
			}
		}

		/// <summary>
		/// Get or set the Description
		/// </summary>
		public object Description
		{
			get { return (object)GetValue(ContentProperty); }
			set { SetValue(ContentProperty, value); }
		}

		/// <summary>
		/// Identifies the Description dependency property
		/// </summary>
		public static readonly DependencyProperty DescriptionProperty =
			DependencyProperty.Register("Description", typeof(object), typeof(PowerToolTip), new UIPropertyMetadata(""));


		/// <summary>
		/// Gets or set the shortcut string
		/// </summary>
		public string Shortcut
		{
			get { return (string)GetValue(ShortcutProperty); }
			set { SetValue(ShortcutProperty, value); }
		}

		/// <summary>
		/// Identifies the Shortcut dependency property
		/// </summary>
		public static readonly DependencyProperty ShortcutProperty =
			DependencyProperty.Register("Shortcut", typeof(string), typeof(PowerToolTip), new UIPropertyMetadata("SHORTCUT"));





		/// <summary>
		/// Get or set the Shortcut Visibility
		/// </summary>
		public Visibility ShortcutVisiblity
		{
			get { return (Visibility)GetValue(ShortcutVisiblityProperty); }
			set { SetValue(ShortcutVisiblityProperty, value); }
		}


		/// <summary>
		/// Identifies the Shortcut Visiblity dependency property
		/// </summary>
		public static readonly DependencyProperty ShortcutVisiblityProperty =
			DependencyProperty.Register("ShortcutVisiblity", typeof(Visibility), typeof(PowerToolTip), new UIPropertyMetadata(Visibility.Collapsed));




	}
}
